package com.example.sihookuiklydemo.utils

import com.tencent.kuikly.core.base.IPagerId

fun IPagerId.getShowHeightString(height: Int, heightUnit:Int): String {

    if (heightUnit == 1) {
        val (feet, inches) = height.toFeetInches()
        val ftString = getLanguage("common_unit_foot", "")
        val inString = getLanguage("common_unit_inch", "")
        return "${feet} ${ftString} ${inches} ${inString}"

    } else {

        return "${height} cm"
    }
}

// 扩展函数：转换为英尺英寸格式
fun Int.toFeetInches(): Pair<Int, Int> {
    val feet = this / 30.48f
    val intFeet = feet.toInt()
    val rawInch = (feet - intFeet) * 12
    val inch = (rawInch + 0.5f).toInt()

    return if (inch >= 12) (intFeet + 1) to (inch % 12)
    else intFeet to inch
}

/**
 * 将英尺和英寸转换为厘米
 *
 * @param feet 英尺 (整数部分)
 * @param inches 英寸 (通常0-11之间的整数)
 * @return 厘米数(四舍五入到整数)
 */
fun feetInchesToCentimeters(feet: Int, inches: Int): Int {
    // 1英尺 = 30.48厘米, 1英寸 = 2.54厘米
    val feetToCm = feet * 30.48f
    val inchesToCm = inches * 2.54f
    val totalCm = feetToCm + inchesToCm

    // 四舍五入到最接近的厘米
    return (totalCm + 0.5f).toInt()
}
